import os
from langchain.memory import ConversationEntityMemory
from langchain.chains import ConversationChain
from langchain.memory.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
from langchain.llms import OpenAI
os.environ["OPENAI_API_KEY"] = '读者申请的OpenAI API Key'
llm = OpenAI(temperature = 0)
conversation_with_memory = ConversationChain(llm=llm, verbose=True, prompt=ENTITY_MEMORY_CONVERSATION_TEMPLATE, memory=ConversationEntityMemory(llm=llm))
conversation_with_memory.predict(input="Mark是Kate的男朋友，他们都在北京上大学")
conversation_with_memory.predict(input="他们都很喜欢学习，Mark目前正在进行人工智能领域的研究")
conversation_with_memory.predict(input="Kate学习新闻传播相关的专业，她希望采访Mark一些关于人工智能领域最新进展的事情")
conversation_with_memory.predict(input="你对Mark和Kate了解多少呢？")